登录 白背景

520. 检测大写字母

https://leetcode-cn.com/problems/detect-capital/

  • 提交时间:2021-11-12 17:48:24
  • 执行用时:0 ms, 在所有 Go 提交中击败了100.00%的用户
  • 内存消耗:2 MB, 在所有 Go 提交中击败了74.39%的用户
  • 通过测试用例:550 / 550
func detectCapitalUse(word string) (ans bool) {
    ans = true
    for index, ascii := range word {
        if index == 0 {
            continue
        }
        if word[0] > 91 && ascii < 91 {
            ans = false
            break
        }
        if index > 1 && word[0] < 91 {
            if word[1] < 91 && ascii > 91 {
                ans = false
                break
            }
            if word[1] > 91 && ascii < 91 {
                ans = false
                break
            }
        }
    }
    return
}